package com.tjtt.tdm.flow.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import com.tjtt.common.utils.TotalFlowXmlTool;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.exception.DaoException;
import com.tjtt.tdm.flow.bean.Flowstate;
import com.tjtt.tdm.flow.bean.Flowtype;
import com.tjtt.tdm.flow.bean.StepEntity;
import com.tjtt.tdm.flow.service.IFlowformService;
import com.tjtt.tdm.flow.service.IFlowtypeService;
import com.tjtt.tdm.form.bean.AutoFormsNew;

public class FlowformAction extends BaseAction {
	private static final long serialVersionUID = -8282568955946054881L;
	private IFlowformService flowformService;
	public IFlowformService getFlowformService() {
		return flowformService;
	}
	public void setFlowformService(IFlowformService flowformService) {
		this.flowformService = flowformService;
	}
	private IFlowtypeService flowtypeService;
	
	/*
	 * 获得发起页面的地址
	 */
	public void getAddpath() {
		String flowid = this.getRequest().getParameter("flowid");
		String stateid = this.getRequest().getParameter("stateid");
		PrintWriter out = PubMethod.GetPrintWriter();
		String addpath = "";
		try {
			Flowtype flowtype = flowtypeService.GetFlowtypeById(Long.parseLong(flowid));
			String filename = flowtype.getFilename();
			String path = PubMethod.GetFlowFilePath()+filename;
			TotalFlowXmlTool fxs = new TotalFlowXmlTool(path);
			if (stateid==null){
				stateid = fxs.GetFlowBeginState().getStateid();
			}
			Flowstate flowstate1 = fxs.GetFlowStateByID(stateid);
			addpath = flowstate1.getForm();
//			if (addpath.indexOf(",")>=0){
//				addpath = "";
//			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String output = "{\"addpath\":\""+addpath+"\"}";
		out.print(output);
	}
	
	

	public IFlowtypeService getFlowtypeService() {
		return flowtypeService;
	}
	public void setFlowtypeService(IFlowtypeService flowtypeService) {
		this.flowtypeService = flowtypeService;
	}
}
